package ac.il.technion.c236369.hw4.typehandlers.tsp.templates.producers;

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Map;

import ac.il.technion.c236369.hw4.core.entity.SizedContentProducer;
import ac.il.technion.c236369.hw4.typehandlers.tsp.templates.TSPTemplate;
import ac.il.technion.c236369.hw4.typehandlers.tsp.templates.TSPTemplateLoader;

/**
 * @author Artem Barger, Maxim Aizenshtein
 *
 *
 *	Load, parse and compile content of tsp file load 
 *	in memory compiled result and process it with 
 *	http params received.
 */
public class TSPContentProducer extends SizedContentProducer {

	private Map<String, String> params;
	private TSPTemplate template;

	public TSPContentProducer( File file, Map<String, String> params) {
		this.params = params;
		TSPTemplateLoader templateLoader = new TSPTemplateLoader(file);
		template = templateLoader.getInstance();
	}
	
	@Override
	public void writeTo(OutputStream outstream) throws IOException {
		template.process( new PrintStream(outstream), params);
	}
}
